<html>
<head>
<script type="text/javascript" src="js/ui.dropdownchecklist.js"></script>
<script type="text/javascript">
	var aJaxURL			= "server-side/operations/warehouse.action.php";					//server side folder url
	var list_JaxURL		= "server-side/operations/warehouse/list.action.php";				//server side folder url
	var seoyURL			= "server-side/seoy/seoy.action.php";								//server side folder url
	var tName			= "example";														//table name
	var fName			= "add-edit-form";													//form name
	var localID			= "";
	var barcodetype		= "";
    var tbName			= "tabs";															//tabs name
    var o_type			= 1;																//Overhead Type start value
    var parent_id		= 0;																//Main Overhead ID if sub Overhead
    var req				= "";
    var in_l            = ""
    var sort_type       = "";   

	$(document).ready(function () {
		$( "#radio" ).buttonset().click(function( event ) {	        
			sort_type=$(event.target).val();
	        LoadTable();
	    });		
		LoadTable();
		GetTabs(tbName);
		//gsUnity.GetTabs(tbName);
		/* Add Button ID, Delete Button ID */
		GetButtons("add_reserve_button", "delete_button");
		GetButtons("cartridge_receive", "delete_button_in1");
		GetButtons("", "delete_button_in2");
		GetButtons("", "delete_button_in3");
		GetButtons("", "delete_button_in4");
		GetButtons("delete_button_in5");
		GetButtons("add_barcode_input2");

		//GetButtons("", "delete_button_in3");

		Check(30000,aJaxURL);
	    $("#add-edit-form").on("dialogclose", function() {
	    	$("#chechedStatus").val("true");
	    });
	    $("#cartridge-receive-form").on("dialogclose", function() {
	    	$("#chechedStatus").val("true");
	    });
	});

    $(document).on("tabsactivate", "#tabs", function() {
    	var type = GetSelectedTab(tbName);
    	GetIN(type);
    });

	//SeoY
	$(document).on("click", ".combobox", function (event) {
		var i = $(this).text();
		$("#" + i).autocomplete( "search", "" );
	});

	$(document.body).click(function (e) {
		$("#client_object").autocomplete("close");
		$("#cartridge_model").autocomplete("close");
		$("#barcode_client").autocomplete("close");
		$("#barcode_cartridge").autocomplete("close");
    	$("#barcode_printer").autocomplete("close");
	});

	function LoadTable(table){
		switch(table){
			case 'prod_list':
				var id = $("#wareHouse").val();
				GetDataTable("prod_list", list_JaxURL, "get_list", 5, "id="+id, 0, "");
				break;
			case 'packing_list' :
				GetDataTable("packing_list", list_JaxURL, "get_packin_list", 2, "", 0, "");
				break;
			case 'inner_packing_list' :
				GetDataTable("inner_packing_list", list_JaxURL, "get_inner_packin_list", 2, "", 0, "");

				break;
			case 'reserve_list' :
				GetDateTimes("end_date");
				GetDataTable("reserve_list", list_JaxURL, "get_list", 3, "", 0, "");
				break;
			case 'list' :
				GetButtons("add_barcode_input", "delete_button","add_barcode");
				GetButtons("", "delete_button_list");
				var id = $("#wareHouse").val();
				GetDataTable("prod_list", list_JaxURL, "get_list", 5, "id="+id, 0, "");
				SetEvents("", "delete_button_list", "", "prod_list", "inner-pack-form" , list_JaxURL);
				LoadTable(in_l);
				break;
			case 'in1' :
				GetDataTable_not_sort("in1", aJaxURL, "get_list&status="+2, 8,"", 0);	
				SetEvents("", "delete_button_in1", "", "in1", fName , aJaxURL);
				in_l = 	"in1";
				break;

			case 'in2' :

				GetDataTable_not_sort("in2", aJaxURL, "get_list&status="+4, 8);
				SetEvents("", "delete_button_in2", "", "in2", fName , aJaxURL);
				in_l = 	"in2";
				break;
			case 'in3' :

				GetDataTable_not_sort("in3", aJaxURL, "get_list&status="+5, 8);
				SetEvents("", "delete_button_in3", "", "in3", fName , aJaxURL);
				in_l = 	"in3";
				break;
			case 'in4' :
				GetDataTable_not_sort("in4", aJaxURL, "get_list&status="+7, 8);
				SetEvents("", "delete_button_in4", "", "in4", fName , aJaxURL);
				in_l = 	"in4";
				break;
			case 'in5' :
				
				GetDataTable_not_sort("in5", aJaxURL, "get_list&status="+8, 8,"", 0);				
				SetEvents("", "delete_button_in5", "", "in5", fName , aJaxURL+"?tab=in5");
				in_l = 	"in5";
				break;	

			case 'res' :
				SetEvents("", "delete_button_in4", "", "in4", fName , aJaxURL);
				GetDataTable_not_sort("res", aJaxURL, "get_list&status="+6, 8, "", 0,  "", 1, "desc");
				in_l = 	"res";
				break;

			default		:
				GetDataTable_not_sort("in", aJaxURL, "get_list&status="+0+"&sort_type="+sort_type, 8,"", 0);		
				SetEvents("", "delete_button", "", "in", fName , aJaxURL);
				in_l = 	"";
				break;
		}

	}

	function LoadDialog(form){
		switch(form){
			case 'cartridge-receive-form' :
				var buttons = {
			        "add_barcode": {
		                text: "შტრიხკოდის ბეჭდვა",
		                id: "add_barcode1",
		                click: function () {
		                }
		            },
			        "cancel": {
		                text: "დახურვა",
		                id: "cancel-dialog",
		                click: function () {
		                	$(this).dialog("close");
		                }
		            }
				};
				GetDialog("cartridge-receive-form", 420, "auto", buttons);
				LoadTable("receive_list");
				GetButtons("add_barcode_input1", "");
				$("#location").focus();

				$(document).on("change", "#status",function(){
					$("#add_barcode_input1").focus();
			    });

				$(document).on("change", "#location",function(){
					$("#status").focus();
			    });

				$("#cartridge-receive-form").bind("dialogclose", function(event) {
					$("#add_barcode_input").focus();
				});

				break;
			case 'add-barcode' :
				SeoY("barcode_client", seoyURL, "barcode_client", "", 0);
				SeoY("barcode_cartridge", seoyURL, "barcode_cartridge", "", 0);
				SeoY("barcode_printer", seoyURL, "barcode_printer", "", 0);

				var add_barcode_buttons = {
		            "print-save": {
		                text: "შენახვა + დაბეჭდვა",
		                id: "print-save-dialog",
		                click: function () {
		                	SaveBarcode(true);
		                }
		            },
			        "cancel": {
		                text: "დახურვა",
		                id: "cancel-dialog",
		                click: function () {
		                	$(this).dialog("close");
		                }
		            }
				};
				GetDialog("add-barcode-form", 500, "auto", add_barcode_buttons);
				$("#barcode_client").val( $("#wareHouseClient").val() );

				$("#add-barcode-form").bind("dialogclose", function(event) {
					$("#add_barcode_input").focus();
				});

				break;
			case 'inner-pack-form' :
				var inner_packing_buttons = {
			        "print-barcode": {
		                text: "სტიკერის ბეჭდვა",
		                id: "print-barcode",
		                click: function () {

		                	printBar();
		                	$("#add_barcode_input").focus();
		                }
		            },
			        "save-packing": {
		                text: "შეფუთვა",
		                id: "save_inner_packing",
		                click: function () {
		            		pack( $("#wareHouseDetailID_packing").val(),"inner_pack");
		            		$(this).dialog("close");
		            		$("#add_barcode_input").focus();
		                }
		            },
			        "save-and-print": {
		                text: "შეფუთვა + ბეჭდვა",
		                id: "save-and-print",
		                click: function () {
		                	$("#add_barcode_input").focus();
		                	printBar();
		            		pack( $("#wareHouseDetailID_packing").val(),"inner_pack");
		            		$(this).dialog("close");
		                }
		            },
			        "cancel": {
		                text: "დახურვა",
		                id: "cancel-dialog",
		                click: function () {
		                	$(this).dialog("close");
		                	$("#add_barcode_input").focus();
		                }
		            }
				};
				LoadTable('inner_packing_list');
				GetDialog("inner-pack-form",550, "auto", inner_packing_buttons);

				if( $("#letterStatus").val() == 0){
					$("#save_inner_packing").attr("disabled", "disabled");
				}

				$("#inner-pack-form").bind("dialogclose", function(event) {
					$("#add_barcode_input").focus();
				});

				break;
			default		:
					var buttons = {
			        "move_unknown": {
		                text: "გასარკვევსი გადატანა",
		                id: "move_unknown",
		                click: function () {
		                	$("#move_unknown_div").remove();
		    				var but = {
		    				        "move_to_unknown": {
		    			                text: "გადატანა",
		    			                id: "move_to_unknown",
		    			                click: function () {
			    			                data= { act :"move_unknown",
			    			                		id  :$("#wareHouse").val(),
			    			                		text:$("#move_unknown_comment").val()   
					    			                }		    			                    
		    			                	$.getJSON(aJaxURL, data, function( data ) {
			    			                	LoadTable(in_l)
		    			                		 $( "#add-edit-form" ).dialog( "close" );
		    			                		 $("#move_unknown_div").remove();
			    			                	}); 
		    			                }
		    			            }
		    					};
			                ////////////////////////////////////////////////////---------------------------------------------------------------------
		    	           data= { act :"comment",
	  			                   id  :$("#wareHouse").val()}   
		    				$.getJSON(aJaxURL, data, function( data ) {
		                	$("body").append("<div id='move_unknown_div' title='კომენტარი'> შემოიტანეთ კომენტარი<textarea id='move_unknown_comment' class='inpt' '>"+data.comment+"</textarea></div>");		                	  
		                	GetDialog("move_unknown_div", "auto", "auto",but);});
		                	//alert($("#wareHouse").val());
		                }
		            },
					 "print_blank": {
			                text: "ბლანკის ბეჭდვა",
			                id: "print_blank",
			                click: function () {
			                	var id = $("#wareHouse").val();

			        	    	var link = GetRootDIR();

			        	    	if($("#letterStatus").val() == 2 ){
				        	    	link = link + "server-side/print/pwork_blank.php?id="+id;
			        	    	}else if($("#letterStatus").val() == 1 ) {
				        	    	link = link + "server-side/print/cwork_blank.php?id="+id;
			        	    	}else{
				        	    	link = link + "server-side/print/rwork_blank.php?id="+id;

			        	    	}

			        	    	var newWin = window.open(link, "JSSite", "width=800,height=800,resizable=yes,scrollbars=yes,status=yes");
			        	    	//newWin.focus();
			        	    	newWin.onload = function() {
			        	    		newWin.print();
			        	    	}
			        	    	newWin.focus();
			        	    	setInterval(function() {
			        	    		newWin.close();
			        	    	}, 1500);
			                }
			            },
				        "pack": {
			                text: "შეფუთვა",
			                id: "pack",
			                click: function () {
			                	var id = $("#wareHouse").val();
							    $.ajax({
							        url: aJaxURL,
								    data: "act=packing_list&id="+id,
							        success: function(data) {
										if(typeof(data.error) != "undefined"){
											if(data.error != ""){
												alert(data.error);
											}else{
												$("#packing-form").html(data.page);
												var packing_buttons = {
												        "save-packing": {
											                text: "შენახვა",
											                id: "save_packing",
											                click: function () {
																$("#pack").css("display", "none");
											            		pack( $("#wareHouseID_packing").val(),"pack");
											            		$(this).dialog("close");
											            		LoadTable();
											                }
											            },
												        "cancel": {
											                text: "დახურვა",
											                id: "cancel-dialog",
											                click: function () {
											                	$(this).dialog("close");
											                }
											            }
												};
												GetDialog("packing-form", 550, "auto",packing_buttons);
												LoadTable('packing_list');
											}
										}
								    }
							    });
			                }
			            },
				        "receive": {
			                text: "მიღება",
			                id: "receive",
			                click: function () {
				                Recive();
			                }
			            },
				        "send": {
			                text: "წარმოებაში გაშვება",
			                id: "send-producing",
			                click: function () {
			                	SendProducing();
			                }
			            },
						"print-packed": {
			                text: "გარე სტიკერის ბეჭდვა",
			                id: "print-packed",
			                click: function () {
								printPacked();
			            		LoadTable();
			            		$("#add_barcode_input").focus();
			                }
			            },
				        "cancel": {
			                text: "დახურვა",
			                id: "cancel-dialog",
			                click: function () {
			                	$(this).dialog("close");
			                	LoadTable();
			                }
						}
				};



				GetDialog(fName, 800, "auto",buttons);

				$("#chechedStatus").val("false");

				var status = $("#wareHouseStatus").val();
				switch(status){
				
					case "0" :
						$("#pack").css("display", "none");
						$("#send-producing").css('display','inline-block');
						$("#receive").css('display','inline-block');
						$("#print-packed").css("display", "none");
					  break;
					case "1" :
						$("#pack").css("display", "none");
						$("#receive").css("display", "none");
						$("#send-producing").css('display','inline-block');
						$("#print-packed").css("display", "none");
					  break;
					case "2" :
						$("#pack").css("display", "none");
						$("#send-producing").css("display", "none");
						$("#receive").css("display", "none");
						$("#print-packed").css("display", "none");
					  break;
					case "3" :
						$("#pack").css("display", "none");
						$("#send-producing").css("display", "none");
						$("#receive").css("display", "none");
						$("#print-packed").css("display", "none");
					  break;
					case "4" :
						$("#pack").css('display','inline-block');
						$("#send-producing").css("display", "none");
						$("#receive").css("display", "none");
						$("#print-packed").css("display", "none");
					  break;  
					default:
						$("#pack").css("display", "none");
						$("#send-producing").css("display", "none");
						$("#receive").css("display", "none");
					  break;
				}
				LoadTable('list');
				if( $("#letterStatus").val() == 0){
					$("#pack").attr("disabled", "disabled");
				}
				$("#add_barcode_input").focus();

			    if(in_l=="in5"){				   
			    	$(".ui-dialog-buttonset button, #add-edit-form button, #add_barcode_input").remove();
			    	//$(".ui-dialog-buttonset").append("<button id='unknown_return'>დაბრუნება</button>");
			    	//$(".ui-dialog-buttonset").append("<button id='save_comment'>შენახვა</button>")
			    	$("#add-edit-form #button_area").append("<button id='unknown_return'>უკან სიაში დაბრუნება</button>");
			    	$("#add-edit-form #button_area").append("<button id='save_comment'>შენახვა</button>")
			    	$("#unknown_return").button().click(function() {
		                data= { act :"unknown_return",
		                		id  :$("#wareHouse").val(),
		                		text:$("#move_unknown_comment").val()   
    			                }				    	
	                	$.getJSON(aJaxURL, data, function( data ) {
		                	 LoadTable(in_l);
		                	 $( "#add-edit-form" ).dialog( "close" );
		                	});			            
			        });	
			    	$("#save_comment").button().click(function() {
		                data= { act :"save_comment",
		                		id  :$("#wareHouse").val(),
		                		text:$("#comment_text").val()   
    			                }	
		                console.log(data)			    	
	                	$.getJSON(aJaxURL, data, function( data ) {		                	
		                	console.log(data)
		                	});			            
			        });	

			        	    	
			    	}
		}

	}
	///////////////---------------------------------------------------------------------------
	$(document).on("keydown", "#add_barcode_input2", function (event) {
		if (event.keyCode == $.ui.keyCode.ENTER){
			param 			= new Object();
        	param.act		= 'get_warehouse_id';
        	param.barcode	= $("#add_barcode_input2").val();
			if(param.barcode.length == 15){
			    $.ajax({
			        url: aJaxURL,
				    data: param,
			        success: function(data) {
						if(typeof(data.error) != "undefined"){
							if(data.error != ""){
								alert(data.error);
							}else{

								param1 			= new Object();
					        	param1.act		= 'get_edit_page';
					        	param1.id	= data.warehouseID;
							    $.ajax({
							        url: aJaxURL,
								    data: param1,
							        success: function(data) {
										if(typeof(data.error) != "undefined"){
											if(data.error != ""){
												alert(data.error);
											}else{
												$("#"+'add-edit-form').html(data.page);
												LoadDialog('add-edit-form');
												GetCartidgeDialog(param.barcode);
											}
										}
								    }
							    });

							}
						}
				    }
			    });
			} else   alert("შტრიხკოდი არასწორია!");
		    $("#barcode_input").val("");
			event.preventDefault();					//Clear Dialog Default <b>keypress<b> Event
        }
	});
	function GetCartidgeDialog(barcode){
		if(barcode.length != 15 ){
			alert("შტრიხკოდი არასწორია!");
			$("#add_barcode_input").val("");

		}else if( $("#wareHouseStatus").val() > 2   ){
			param 			= new Object();
			param.act		= "get_edit_page";
			param.wareHouse = $("#wareHouse").val();
			param.barcode 	= barcode;
		    $.ajax({
		        url: list_JaxURL,
			    data: param,
		        success: function(data) {
					if(typeof(data.error) != "undefined"){
						if(data.error != ""){
							alert(data.error);
							$("#add_barcode_input").val("");
						}else{
							$("#inner-pack-form").html(data.page);
							LoadDialog("inner-pack-form");
							$("#add_barcode_input").val("");
						}
					}
			    }
		    });

		}else{
			param 			= new Object();
			param.act		= "add_barcode";
			param.wareHouse = $("#wareHouse").val();
			param.barcode 	= barcode;
		    $.ajax({
		        url: list_JaxURL,
			    data: param,
		        success: function(data) {
					if(typeof(data.error) != "undefined"){
						if(data.error != ""){
							alert(data.error);
						}else{
							LoadTable("list");
						}
					}
			    }
		    });
			$("#add_barcode_input").val("");
			$("#add_barcode_input").focus();
		}
		event.preventDefault();					//Clear Dialog Default <b>keypress<b> Event

	}
	$(document).on("keydown", "#add_barcode_input", function (event) {
		if (event.keyCode == $.ui.keyCode.ENTER){
			var barcode = $("#add_barcode_input").val();
			GetCartidgeDialog(barcode);

		}
	});

	$(document).on("keydown", "#add_barcode_input1", function (event) {
		if (event.keyCode == $.ui.keyCode.ENTER){
			var barcode 	= $("#add_barcode_input1").val();
			var location	= $("#location").val();

			$("#add_barcode_input1").val("");
			var condition = $("#status").val();
			if(condition == 0){
				alert("შეიყვანეთ კატრიჯის მდგომარეობა!");
			}else if(barcode.length != 15 ){
				alert("შტრიხკოდი არასწორია!");
			}else if( location == 0 ){
				alert("შეიყვანეთ საქყობის სახელი!");
			}else{
        		param = new Object();
        	    //Action
        		param.act		= "change_location";
        		param.barcode	= barcode;
        		param.location	= location;
        		param.condition	= condition;

			    $.ajax({
			        url: aJaxURL,
				    data: param,
			        success: function(data) {
						if(typeof(data.error) != "undefined"){
							if(data.error != ""){
								alert(data.error);
							}else{
							}
						}
				    }
			    });
			}
			$("#add_barcode_input1").focus();

			event.preventDefault();					//Clear Dialog Default <b>keypress<b> Event
		}
	});

	$(document).on("click", "#add_reserve_button", function (event) {
		ClearDB();
		param = new Object();
	    //Action
		param.act	= "get_add_page";
		localID			= GetLocalID();

	    $.ajax({
	        url: aJaxURL,
		    data: param,
	        success: function(data) {
				if(typeof(data.error) != "undefined"){
					if(data.error != ""){
						alert(data.error);
					}else{
						var buttons = {
						        "save": {
						            text: "დამატება",
						            id: "save_reserve",
						            click: function () {
						        		param = new Object();
						        	    //Action
						        		param.act	= "save_reserve";
						        		param.id	= localID;
						        		param.clObj	= $("#client_object").val();
						        		param.date  = $("#end_date").val();

								        if($('#reserve_list tbody tr td').length <= 1){
							        		alert("კარტრიჯების სია ცარიელია!");
						        		}else{
							        		 $.ajax({
										        url: aJaxURL,
											    data: param,
										        success: function(data) {
													if(typeof(data.error) != "undefined"){
														if(data.error != ""){
															alert(data.error);
														}else{
															$("#add-edit-form").dialog("close");
															LoadTable();
														}
													}
											    }
										    });
						        		}
						            }
						        },
						        "cancel": {
					                text: "დახურვა",
					                id: "cancel-dialog",
					                click: function () {
					                	$(this).dialog("close");
					                }
					            }
						};
						$("#add-edit-form").html(data.page);
						SeoY("client_object", seoyURL, "client_objects", "", 0);



						$(document).on("click", "#client_object-widget", function () {
							var client_name = $("#client_object").val();
							var clientID = GetClientID(client_name);
							$(".inner-table").find(":input").prop("disabled", false);
							$("#client_object").attr("disabled", "disabled");
							$("#client_object_btn").attr("disabled", "disabled");
							event.preventDefault();					//Clear Dialog Default <b>keypress<b> Event

							SeoY("cartridge_model", seoyURL, "client_cartridge", "id=" + clientID, "", 0);
						});



						LoadTable("reserve_list");
						GetDialog("add-edit-form",550, "auto", buttons);
						$("#chechedStatus").val("false");
					}
				}
		    }
	    });

	});

	$(document).on("click", "#cartridge_receive", function (event) {
		param = new Object();
	    //Action
		param.act	= "get_receive_page";

	    $.ajax({
	        url: list_JaxURL,
		    data: param,
	        success: function(data) {
				if(typeof(data.error) != "undefined"){
					if(data.error != ""){
						alert(data.error);
					}else{
						$("#cartridge-receive-form").html(data.page);
						LoadDialog("cartridge-receive-form");
						$("#chechedStatus").val("false");
					}
				}
		    }
	    });

	});

	$(document).on("click", "#add_barcode", function (event) {
		if( $("#letterStatus").val() == 1 || $("#letterStatus").val() == 0 ){
			$.ajax({
			       url: list_JaxURL,
				   data: "act=add_cbarcode_page",
			       success: function(data) {
						if(typeof(data.error) != "undefined"){
							if(data.error != ""){
								alert(data.error);
							}else{
								$("#add-barcode-form").html(data.page);
								LoadDialog("add-barcode");
							}
						}
				    }
			});
		}else{
			$.ajax({
			       url: list_JaxURL,
				   data: "act=add_pbarcode_page",
			       success: function(data) {
						if(typeof(data.error) != "undefined"){
							if(data.error != ""){
								alert(data.error);
							}else{
								$("#add-barcode-form").html(data.page);
								LoadDialog("add-barcode");
							}
						}
				    }
			});
		}
	});

	$(document).on("click", "#add_barcode1", function (event) {
			$.ajax({
			       url: list_JaxURL,
				   data: "act=add_cbarcode_page",
			       success: function(data) {
						if(typeof(data.error) != "undefined"){
							if(data.error != ""){
								alert(data.error);
							}else{
								$("#add-barcode-form").html(data.page);
								LoadDialog("add-barcode");
							}
						}
				    }
			});
	});

	$(document).on("keydown", "#quantity", function (event) {
		if (event.keyCode == $.ui.keyCode.ENTER){
			client_object	= $("#client_object").val();
			cartridge_model	= $("#cartridge_model").val();
			quantity		= $("#quantity").val();


			if(client_object== ''){
				alert('შეიყვანეთ კლიენტი');
			}else if(cartridge_model == ''){
				alert('შეიყვანეთ მოდელი');
			}else if(quantity == '0' || quantity == ''){
				alert('შეიყვანეთ რაოდენობა');
			}else{
				$("#client_object").attr("disabled", "disabled");
				$("#client_object_btn").button("disable");
				GetDataTable("reserve_list", aJaxURL , "get_reserve_list", 4, "ct=" +cartridge_model+"&q="+quantity + "&localiD=" + localID, 0, "");
			}
			event.preventDefault();					//Clear Dialog Default <b>keypress<b> Event
		}
	});

    function SaveBarcode(print){
    	if( $("#letterStatus").val() == 1 || $("#letterStatus").val() == 0){
        	var barcode_aJaxURL = "server-side/view/barcode.action.php";		//server side folder url
    		param = new Object();

            //Action
        	param.act	= "save_barcode";

    	    param.id	= $("#barcode_id").val();

    	    param.t		= $("#type").val();
    	    param.bcl	= $("#barcode_client").val();
    	    param.bct	= $("#barcode_cartridge").val();
    	    param.ob	= $("#old_barcode").val();
    	    param.c     = $("#count").val();
    	}else{
        	var barcode_aJaxURL = "server-side/view/printer_barcode.action.php";		//server side folder url
    		param = new Object();

            //Action
	    	param.act	= "save_barcode";
		    param.bcl	= $("#barcode_client").val();
		    param.bp	= $("#barcode_printer").val();
		    param.sn	= $("#serial_number").val();
    	}

		if(param.t == 0){
			alert("შეავსეთ კარტრიჯის ტიპი!");
		}else if(param.bcl == 0){
			alert("შეავსეთ კლიენტის დასახელება!");
		}else if(param.bct == 0){
			alert("შეავსეთ კარტრიჯის დასახელება!");
		}else{
		    $.ajax({
		        url: barcode_aJaxURL,
			    data: param,
		        success: function(data) {
					if(typeof(data.error) != "undefined"){
						if(data.error != ""){
							alert(data.error);
						}else{
							if(print){
								GetPrintPage(data.barcode_list);
								$("#add-barcode-form").dialog("close");
							}
						}
					}
			    }
		    });
		}
	}

    function GetPrintPage(barcode_list){
    	param = new Object();

        //Action
    	param.act	= "get_barcode";

	    param.list	= barcode_list;

    	var data = GetAjaxData(param);
    	var link = GetRootDIR();

    	link = link + "server-side/print/print.action.php?" + data;

    	var newWin = window.open(link, "JSSite", "width=800,height=800,resizable=yes,scrollbars=yes,status=yes");
    	newWin.focus();
    	newWin.onload = function() {
    		newWin.print();
    	}
    }

	function GetLocalID(){
		var local_id;
		$.ajax({
			url: aJaxURL,
			async: false, //r-value
			data: "act=get_local_id",
			success: function(data) {
				if(typeof(data.error) != "undefined"){
					if(data.error != ""){
						alert(data.error);
					}else{
						local_id = data.local_id;
					}
				}
			}
		});
		return local_id;
	}

	function ClearDB() {
		$.ajax({
			url: aJaxURL,
	 		data: "act=clear_db",
	  		success: function(data) {
	 			if (typeof(data.error) != "undefined") {
					if (data.error != "") {
						alert(data.error);
	  				}
				}
			}
		});
	}

	function GetClientID(client_name){
		var client_id;
		$.ajax({
	        url: aJaxURL,
    		async: false, //r-value
		    data: "act=get_client_id&cn=" + client_name,
	        success: function(data) {
				if(typeof(data.error) != "undefined"){
					if(data.error != ""){
						alert(data.error);
					}else{
						client_id = data.client_id;
					}
				}
		    }
	    });
      	return client_id;
	}

	function pack(id,pack_type){
        var data = $(".check:checked").map(function () { //Get Checked checkbox array
            return this.value;
        }).get();

        var parts = [];

        for (var i = 0; i < data.length; i++) {
        	parts.push(data[i]);
        }

    	param = new Object();
        //Action
    	param.act	= pack_type;
	    param.parts	= parts;
	    param.id	= id;
	    if(pack_type == "pack"){
	    	param.type = $("#letterStatus").val();
	    }

	    var link	=  GetAjaxData(param);

        $.ajax({
            url: aJaxURL,
            data: link,
            dataType: "json",
            success: function (data) {
                if (data.error != "") {
                    alert(data.error);
                } else {
                	LoadTable("in2");
                    LoadDialog('packing_list');
                }
            }
        });

        $("#add_barcode_input").focus();
	}

	function SendProducing(){
		param 			= new Object();
		param.act		= "check_barcodes";
		param.id		 = $("#wareHouse").val();
	    $.ajax({
	        url: aJaxURL,
		    data: param,
	        success: function(data) {
				if(typeof(data.error) != "undefined"){
					if(data.error != ""){
						alert(data.error);
					}else{
						param 			= new Object();
						param.act		= "send_producing";
						param.id		 = $("#wareHouse").val();
					    $.ajax({
					        url: aJaxURL,
						    data: param,
					        success: function(data) {
								if(typeof(data.error) != "undefined"){
									if(data.error != ""){
										alert(data.error);
									}else{
									    LoadTable();
									}
								}
						    }
					    });
					    $("#"+fName).dialog("close");
					}
				}
		    }
	    });
	}
	///-------------------------------------------------------------------------------
    function del_list(frname){
        var data = $(".check:checked").map(function () { //Get Checked checkbox array
            return this.value;
        }).get();

        for (var i = 0; i < data.length; i++) {
            $.ajax({
                url: aJaxURL,
                type: "POST",
                data: "act=disable&id=" + data[i] ,
                dataType: "json",
                success: function (data) {
                    if (data.error != "") {
                        alert(data.error);
                    } else {
                        $("#" + check).attr("checked", false);
                    }
                }
            });
        }
        //Reload Table
        if ($.isFunction(window.LoadTable)) {
            //execute it
            LoadTable(frname);
        }
    }

	function Recive(){
		param 			= new Object();
		param.act		= "check_barcodes";
		param.id		 = $("#wareHouse").val();
	    $.ajax({
	        url: aJaxURL,
		    data: param,
	        success: function(data) {
				if(typeof(data.error) != "undefined"){
					if(data.error != ""){
						alert(data.error);
					}
			    	var id   = $("#wareHouse").val();
				    $.ajax({
				        url: aJaxURL,
					    data: "act=recive&id="+id,
				        success: function(data) {
							if(typeof(data.error) != "undefined"){
								if(data.error != ""){
									alert(data.error);
								}else{
									$("#receive").css("display", "none");
								}
							}
					    }
				    });
			    	LoadTable();
				}
		    }
	    });
	}

    function GetIN(type) {

        switch(type){
        	case 0 :
        		GetButtons("add_reserve_button", "");
        		GetButtons("cartridge_receive", "");

        		LoadTable("in");
        		break;

        	case 1 :
        		LoadTable("in1");
        		SetEvents("", "", "", "in1", fName , aJaxURL);
        		break;

        	case 2 :
        		LoadTable("in2");
        		SetEvents("", "", "", "in2", fName , aJaxURL);
        		break;

        	case 3:
        		LoadTable("in3");
        		SetEvents("", "", "", "in3", fName , aJaxURL);
        		break;

        	case 4:
        		LoadTable("res");
        		SetEvents("", "", "", "res", fName , aJaxURL);
        		break;
        	case 5:
        		LoadTable("in4");
        		SetEvents("", "", "", "in4", fName , aJaxURL);
        		break;
        	case 6:
        		LoadTable("in5");
        		//SetEvents("", "", "", "in5", fName , aJaxURL);
        		break;	
        	default :
        		LoadTable("in");
    			break;
        }
    }

    function printBar(){
    	param = new Object();

        //Action
    	param.act	= "get_warehous_barcode";

	    param.wdid	=$("#wareHouseDetailID_packing").val();

    	var data = GetAjaxData(param);
    	var link = GetRootDIR();

    	link = link + "server-side/print/print.action.php?" + data;

    	var newWin = window.open(link, "JSSite", "width=800,height=800,resizable=yes,scrollbars=yes,status=yes");
    	newWin.focus();
    	newWin.onload = function() {
    		newWin.print();
    	}

    	setInterval(function() {
    		newWin.close();
    	}, 3000);

    	$("#add_barcode_input").focus();
    }

    function printPacked(){

    	param = new Object();

        //Action
    	param.act	= "full_pack";

	    param.wid	=$("#wareHouse").val();

    	var data = GetAjaxData(param);
    	var link = GetRootDIR();

    	link = link + "server-side/print/print.action.php?" + data;

    	var newWin = window.open(link, "JSSite", "width=800,height=800,resizable=yes,scrollbars=yes,status=yes");
    	newWin.focus();
    	newWin.onload = function() {
    		newWin.print();
    	}

    	setInterval(function() {
    		newWin.close();
    	}, 3000);

    	$("#add_barcode_input").focus();

    }
</script>


<style type="text/css">
    
 .radio {
  background:#C9C9C9 !important;
  border:none !important;	
  color: #fff !important;  	
}

.ui-button.ui-state-active .ui-button-text {
  background-image: linear-gradient(to bottom, #8aaaff, #006db0);
  color: #fff; 
  border-radius:5px; 	
}    
    
</style>

</head>

<body>
	<div id="tabs" style="width: 1060px; margin: 0 auto; min-height: 768px;">
		<ul>
			<li><a href="#tab-in">მიღებული</a></li>
			<li><a href="#tab-out">წარმოებაში</a></li>
			<li><a href="#tab-in1">წარმ. დასრულებული</a></li>
			<li><a href="#tab-out1">შეფუთული</a></li>
			<li><a href="#tab-reserve">დატენილი რეზერვი</a></li>
			<li><a href="#tab-in3">შესრულებულები</a></li>
			<li><a href="#tab-unk">გასარკვევები</a></li>			
		</ul>

	<div id="tab-in">
	    <div id="dt_example" class="ex_highlight_row">
	        <div id="container">
	            <div id="dynamic">
	                <h2 align="center">მიღებული</h2>
		        	<div id="button_area">
		        		<button id="add_reserve_button">დამუხტვა</button>
	        			<button id="cartridge_receive">კატრიჯების მიღება</button>
	        			<button id="delete_button">წაშლა</button>
	        			<div id="radio" style="display: inline;">
	        			 <input type="radio" id="radio0" value=" "  name="radio" checked><label class="radio" for="radio0" >სტანდარტული</label>   
                         <input type="radio" id="radio1" value="districts.`name` DESC ,"  name="radio"><label class="radio"  for="radio1">უბნების მიხედვით</label>
                        </div>  
		        	</div>
	                <table class="display" id="in">
	                    <thead>
	                        <tr id="datatable_header">
	                            <th>ID</th>
	                            <th style="width: 141px" title="დასრულების გეგმიური დრო">დას. გეგმიური დრო</th>
	                            <th style="width: 141px" title="მიტანის გეგმიური დრო">მიტანის  დრო</th>   
	                            <th style="width: 84px;" >ბარათის ნომერი</th>
	                            <th style="width: 100%">ორგანიზაცია</th>
	                            <th style="width: 30px">ჯამი</th>
	                            <th style="width: 120px">პრიორიტეტი</th>
	                            <th style="width: 190px">სტატუსი</th>
	                            <th class="check">#</th>
	                        </tr>
	                    </thead>
	                    <thead>
	                        <tr class="search_header">
	                            <th class="colum_hidden">
	                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_date" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_date" value="ფილტრი" class="search_init" />
	                            </th>
	                             <th>
	                                <input type="text" name="search_date" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>	                            
	                                <input type="text" name="search_aleter" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                            	<input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                           <th>
	                            	<input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
                            	</th>
	                        </tr>
	                    </thead>
	                </table>
	            </div>
	            <div class="spacer">
	            </div>
	        </div>
	    </div>
    </div>
    <div id="tab-out">
    	    <div id="dt_example" class="ex_highlight_row">
	        <div id="container">
	            <div id="dynamic">
	                <h2 align="center">წარმოებაში</h2>
		        	<div id="button_area">
	        			<button id="delete_button_in1">წაშლა</button>
		        	</div>
	                <table class="display" id="in1">
	                    <thead>
	                        <tr id="datatable_header">
	                            <th>ID</th>
	                            <th style="width: 141px" title="დასრულების გეგმიური დრო">დას. გეგმიური დრო</th>
	                            <th style="width: 141px" title="მიტანის გეგმიური დრო">მიტანის  დრო</th>   
	                            <th style="width: 84px;" >ბარათის ნომერი</th>
	                            <th style="width: 100%">ორგანიზაცია</th>
	                            <th style="width: 50px">ჯამი</th>
	                            <th style="width: 120px">პრიორიტეტი</th>
	                            <th style="width: 190px">სტატუსი</th>
	                            <th class="check">#</th>
	                        </tr>
	                    </thead>
	                    <thead>
	                        <tr class="search_header">
	                            <th class="colum_hidden">
	                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_date" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_aleter" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                            	<input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th></th>
	                        </tr>
	                    </thead>
	                </table>
	            </div>
	            <div class="spacer">
	            </div>
	        </div>
	    </div>
    </div>
    <div id="tab-in1">
        	    <div id="dt_example" class="ex_highlight_row">
	        <div id="container">
	            <div id="dynamic">
	                <h2 align="center">წარმ.დასრულებული</h2>
	                <div id="button_area">
	                	<input style="display:inline; " id="add_barcode_input2" type="text" maxlength="15"/>
	        			<button id="delete_button_in2">წაშლა</button>
		        	</div>
	                <table class="display" id="in2">
	                    <thead>
	                        <tr id="datatable_header">
	                            <th>ID</th>
	                            <th style="width: 141px" title="დასრულების გეგმიური დრო">დას. გეგმიური დრო</th>
	                            <th style="width: 141px" title="მიტანის გეგმიური დრო">მიტანის  დრო</th>   
	                            <th style="width: 84px;" >ბარათის ნომერი</th>
	                            <th style="width: 100%">ორგანიზაცია</th>
	                            <th style="width: 50px">ჯამი</th>
	                            <th style="width: 120px">პრიორიტეტი</th>
	                            <th style="width: 190px">სტატუსი</th>
	                            <th class="check">#</th>
	                        </tr>
	                    </thead>
	                    <thead>
	                        <tr class="search_header">
	                            <th class="">
	                            	<input type="text" name="search_id"    value="ფილტრი"  class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_date"   value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_aleter" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                            	<input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
                                    <input type="text" name="search_client" value="ფილტრი" class="search_init" />           
                            	</th>
                            	<th>
                                    <input type="text" name="search_client" value="ფილტრი" class="search_init" />           
                            	</th>
	                            <th></th>
	                        </tr>
	                    </thead>
	                </table>
	            </div>
	            <div class="spacer">
	            </div>
	        </div>
	    </div>
    </div>

    <div id="tab-out1">
        	    <div id="dt_example" class="ex_highlight_row">
	        <div id="container">
	            <div id="dynamic">
	                <h2 align="center">შეფუთული</h2>
	                <table class="display" id="in3">
	                    <thead>
	                        <tr id="datatable_header">
	                            <th>ID</th>
	                            <th style="width: 141px" title="დასრულების გეგმიური დრო">დას. გეგმიური დრო</th>
	                            <th style="width: 141px" title="მიტანის გეგმიური დრო">მიტანის  დრო</th>   
	                            <th style="width: 84px;" >ბარათის ნომერი</th>
	                            <th style="width: 100%">ორგანიზაცია</th>
	                            <th style="width: 50px">ჯამი</th>
	                            <th style="width: 120px">პრიორიტეტი</th>
	                            <th style="width: 190px">სტატუსი</th>
	                        </tr>
	                    </thead>
	                    <thead>
	                        <tr class="search_header">
	                            <th class="">
	                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_date" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_aleter" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                            	<input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th></th>
	                        </tr>
	                    </thead>
	                </table>
	            </div>
	            <div class="spacer">
	            </div>
	        </div>
	    </div>
    </div>

        <div id="tab-reserve">
        	    <div id="dt_example" class="ex_highlight_row">
	        <div id="container">
	            <div id="dynamic">
	                <h2 align="center">რეზერვი</h2>
	                <table class="display" id="res">
	                    <thead>
	                        <tr id="datatable_header">
	                            <th>ID</th>
	                            <th style="width: 141px" title="დასრულების გეგმიური დრო">დას. გეგმიური დრო</th>
	                            <th style="width: 0px" title="მიტანის გეგმიური დრო">მიტანის  დრო</th>   
	                            <th style="width: 84px;" >ბარათის ნომერი</th>
	                            <th style="width: 100%">ორგანიზაცია</th>
	                            <th style="width: 50px">ჯამი</th>
	                            <th style="width: 120px">პრიორიტეტი</th>
	                            <th style="width: 190px">სტატუსი</th>
	                        </tr>
	                    </thead>
	                    <thead>
	                        <tr class="search_header">
	                            <th class="colum_hidden">
	                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_date" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_aleter" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                            	<input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th></th>
	                        </tr>
	                    </thead>
	                </table>
	            </div>
	            <div class="spacer">
	            </div>
	        </div>
	    </div>
    </div>
     <div id="tab-in3">
        	    <div id="dt_example" class="ex_highlight_row">
	        <div id="container">
	            <div id="dynamic">
	                <h2 align="center">შესრულებულები</h2>
	                <div id="button_area">

	        			<button id="delete_button_in4">წაშლა</button>
		        	</div>
	                <table class="display" id="in4">
	                    <thead>
	                        <tr id="datatable_header">
	                            <th>ID</th>
	                            <th style="width: 141px" title="დასრულების გეგმიური დრო">დას. გეგმიური დრო</th>
	                            <th style="width: 141px" title="მიტანის გეგმიური დრო">მიტანის  დრო</th>   
	                            <th style="width: 84px;" >ბარათის ნომერი</th>
	                            <th style="width: 100%">ორგანიზაცია</th>
	                            <th style="width: 50px">ჯამი</th>
	                            <th style="width: 120px">პრიორიტეტი</th>
	                            <th style="width: 190px">სტატუსი</th>
	                            <th class="check">#</th>
	                        </tr>
	                    </thead>
	                    <thead>
	                        <tr class="search_header">
	                            <th class="">
	                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_date" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_aleter" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                            	<input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th></th>
	                        </tr>
	                    </thead>
	                </table>
	            </div>
	            <div class="spacer">
	            </div>
	        </div>
	    </div>
    </div>
         <div id="tab-unk">
        	    <div id="dt_example" class="ex_highlight_row">
	        <div id="container">
	            <div id="dynamic">
	                <h2 align="center">გასარკვევები</h2>
	                <div id="button_area">
	        			<button id="delete_button_in5">წაშლა</button>
		        	</div>
	                <table class="display" id="in5">
	                    <thead>
	                        <tr id="datatable_header">
	                            <th>ID</th>
	                            <th style="width: 141px" title="დასრულების გეგმიური დრო">დას. გეგმიური დრო</th>
	                            <th style="width: 141px" title="მიტანის გეგმიური დრო">მიტანის  დრო</th>   
	                            <th style="width: 84px;" >ბარათის ნომერი</th>
	                            <th style="width: 100%">ორგანიზაცია</th>
	                            <th style="width: 50px">ჯამი</th>
	                            <th style="width: 120px">პრიორიტეტი</th>
	                            <th style="width: 190px">სტატუსი</th>
	                            <th class="check">#</th>
	                        </tr>
	                    </thead>
	                    <thead>
	                        <tr class="search_header">
	                            <th class="colum_hidden">
	                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_date" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_aleter" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                            	<input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th>
	                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
	                            </th>
	                            <th></th>
	                        </tr>
	                    </thead>
	                </table>
	            </div>
	            <div class="spacer">
	            </div>
	        </div>
	    </div>
    </div>
    </div>
	<div>
		<input type="hidden" id="chechedStatus" value="true"/>
    </div>
	<div id="add-barcode-form" class="form-dialog" title="ბლანკი">
    	<!-- aJax -->
	</div>
	<div id="add-edit-form" class="form-dialog" title="ბლანკი">
    	<!-- aJax -->
	</div>
    <div id="packing-form" class="form-dialog" title="შეფუთვა">
    	<!-- aJax -->
	</div>
    <div id="inner-pack-form" class="form-dialog" title="კატრიჯის შეფუთვა">
    	<!-- aJax -->
	</div>
    <div id="cartridge-receive-form" class="form-dialog" title="კატრიჯის მიღება">
    	<!-- aJax -->
	</div>
</body>
</html>